package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HireRegion;
import com.ruoyi.system.service.IHireRegionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地址Controller
 * 
 * @author ruoyi
 * @date 2024-04-26
 */
@Controller
@RequestMapping("/system/region")
public class HireRegionController extends BaseController
{
    private String prefix = "system/region";

    @Autowired
    private IHireRegionService hireRegionService;

    @RequiresPermissions("system:region:view")
    @GetMapping()
    public String region()
    {
        return prefix + "/region";
    }

    /**
     * 查询地址列表
     */
    @RequiresPermissions("system:region:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HireRegion hireRegion)
    {
        startPage();
        List<HireRegion> list = hireRegionService.selectHireRegionList(hireRegion);
        return getDataTable(list);
    }

    /**
     * 导出地址列表
     */
    @RequiresPermissions("system:region:export")
    @Log(title = "地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HireRegion hireRegion)
    {
        List<HireRegion> list = hireRegionService.selectHireRegionList(hireRegion);
        ExcelUtil<HireRegion> util = new ExcelUtil<HireRegion>(HireRegion.class);
        return util.exportExcel(list, "地址数据");
    }

    /**
     * 新增地址
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存地址
     */
    @RequiresPermissions("system:region:add")
    @Log(title = "地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HireRegion hireRegion)
    {
        return toAjax(hireRegionService.insertHireRegion(hireRegion));
    }

    /**
     * 修改地址
     */
    @RequiresPermissions("system:region:edit")
    @GetMapping("/edit/{regionId}")
    public String edit(@PathVariable("regionId") Long regionId, ModelMap mmap)
    {
        HireRegion hireRegion = hireRegionService.selectHireRegionByRegionId(regionId);
        mmap.put("hireRegion", hireRegion);
        return prefix + "/edit";
    }

    /**
     * 修改保存地址
     */
    @RequiresPermissions("system:region:edit")
    @Log(title = "地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HireRegion hireRegion)
    {
        return toAjax(hireRegionService.updateHireRegion(hireRegion));
    }

    /**
     * 删除地址
     */
    @RequiresPermissions("system:region:remove")
    @Log(title = "地址", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hireRegionService.deleteHireRegionByRegionIds(ids));
    }
}
